/*
 * HomeCategoryListItem.java
 * business
 *
 * Created by SunDing on 2016/9/9.
 *
 * Copyright (c) 2016年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.ui.widget.listview.displaylistitem;

import android.app.Activity;
import android.content.Context;
import android.view.View;

import com.yidiandao.business.R;
import com.yidiandao.business.data.imagemodule.Menu;
import com.yidiandao.business.data.imagemodule.MenuInfo;
import com.yidiandao.business.ui.widget.listview.DisplayListItem;
import com.yidiandao.business.ui.widget.listview.viewholder.HomeMenuHolder;
import com.yidiandao.business.utils.JumpUtils;

import java.util.List;

/** 首页酒类 ListItem */
public class HomeMenuListItem extends DisplayListItem<HomeMenuHolder, MenuInfo>
        implements View.OnClickListener {

    private Activity mActivity;

    private Menu mMenu1;
    private Menu mMenu2;
    private Menu mMenu3;
    private Menu mMenu4;
    private Menu mMenu5;
    private Menu mMenu6;
    private Menu mMenu7;
    private Menu mMenu8;

    public HomeMenuListItem(MenuInfo menus) {
        super(menus);
    }

    @Override
    public void onShow(Context context, HomeMenuHolder holder) {

        List<Menu> menuList = data.getMenuList();
        MenuInfo.Font font = data.getFont();

        mActivity = (Activity) context;

        mMenu1 = menuList.get(0);
        mMenu2 = menuList.get(1);
        mMenu3 = menuList.get(2);
        mMenu4 = menuList.get(3);

        try {
            mMenu5 = menuList.get(4);
            mMenu6 = menuList.get(5);
            mMenu7 = menuList.get(6);
            mMenu8 = menuList.get(7);
        } catch (IndexOutOfBoundsException e) {
            holder.setLine2Gone();
        }

        holder.refreshUI(mMenu1, mMenu2, mMenu3, mMenu4, mMenu5, mMenu6, mMenu7, mMenu8);

        holder.mRootMenu1.setOnClickListener(this);
        holder.mRootMenu2.setOnClickListener(this);
        holder.mRootMenu3.setOnClickListener(this);
        holder.mRootMenu4.setOnClickListener(this);
        holder.mRootMenu5.setOnClickListener(this);
        holder.mRootMenu6.setOnClickListener(this);
        holder.mRootMenu7.setOnClickListener(this);
        holder.mRootMenu8.setOnClickListener(this);

        holder.refreshBackground(font);
    }

    @Override
    public String getDisplayItemTag() {
        return HomeMenuListItem.class.getSimpleName();
    }

    @Override
    public Class<HomeMenuHolder> getViewHolderClazz() {
        return HomeMenuHolder.class;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.root_menu_1:
                JumpUtils.clickMenu(mActivity, mMenu1);
                break;
            case R.id.root_menu_2:
                JumpUtils.clickMenu(mActivity, mMenu2);
                break;
            case R.id.root_menu_3:
                JumpUtils.clickMenu(mActivity, mMenu3);
                break;
            case R.id.root_menu_4:
                JumpUtils.clickMenu(mActivity, mMenu4);
                break;
            case R.id.root_menu_5:
                JumpUtils.clickMenu(mActivity, mMenu5);
                break;
            case R.id.root_menu_6:
                JumpUtils.clickMenu(mActivity, mMenu6);
                break;
            case R.id.root_menu_7:
                JumpUtils.clickMenu(mActivity, mMenu7);
                break;
            case R.id.root_menu_8:
                JumpUtils.clickMenu(mActivity, mMenu8);
                break;
        }
    }
}
